package com.ruoyi.consumer.utils.redis;

import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.consumer.service.impl.CCompanyServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: lizhouwei
 * @ date : 2023/11/17
 * @description: 将用户 的公司信息缓存到redis中
 */
@Component
public class CompanyCache {

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private CCompanyServiceImpl companyService;

    //将用户的公司信息缓存到redis中
    public void cacheCompanyInfo(Integer userId, String companyName) {
        redisCache.setCacheObject("companyInfo:" + userId, companyName);
    }

    //从redis中获取用户的公司信息
    public String getCompanyInfo(Integer userId) {
        return redisCache.getCacheObject("companyInfo:" + userId);
    }

    //移除redis中的用户公司信息
    public void removeCompanyInfo(Integer userId) {
        redisCache.deleteObject("companyInfo:" + userId);
    }
}
